package com.ztgf.logistics.api.cms.deppon;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.logistics.models.bo.deppon.LogisticsOrderEditBO;
import com.ztgf.logistics.models.bo.deppon.api.DepponBudgetBO;
import com.ztgf.logistics.models.bo.deppon.api.DepponWebsiteBO;
import com.ztgf.logistics.models.service.deppon.ILogisticsDepponOrderService;
import com.ztgf.logistics.models.vo.deppon.LogisticsOrderVO;
import com.ztgf.logistics.models.vo.deppon.api.DepponBudgetVO;
import com.ztgf.logistics.models.vo.deppon.api.DepponWebsiteListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.logistics.models.service.deppon.ILogisticsOrderService;
import com.ztgf.logistics.models.bo.deppon.LogisticsOrderSaveBO;
import com.ztgf.logistics.models.bo.deppon.LogisticsOrderBO;

import java.util.List;

/**
 * 物流订单表控制器
 *
 * @author mxli
 * @Date 2021-09-13 22:15:56
 */

@RestController
@RequestMapping("/cms/logisticsOrder")
@Slf4j
@Api(value = "LogisticsOrderController",tags = "物流订单表接口")
public class LogisticsOrderController {

    @DubboReference
    private ILogisticsOrderService logisticsOrderService;
    @DubboReference
    private ILogisticsDepponOrderService logisticsDepponOrderService;


    @ApiOperation(value = "添加物流订单表",notes = "添加物流订单表")
    @PostMapping(value = "/insert")
    public Result insert(LogisticsOrderSaveBO saveBO) {
        return logisticsDepponOrderService.add(saveBO);
    }

    @ApiOperation(value = "修改物流订单表",notes = "修改物流订单表")
    @PostMapping("/update")
    public Result update(LogisticsOrderEditBO saveBO){
        return logisticsOrderService.update(saveBO);
    }


    @ApiOperation(value = "撤销物流订单",notes = "撤销物流订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "物流订单表id",required = true,paramType = "query", dataType = "Long")
            ,@ApiImplicitParam(name = "remark",value = "撤销说明",required = true,paramType = "query", dataType = "String")
    })
    @PostMapping("/cancel")
    public Result cancel(@RequestParam("id") Long id, String remark){
        return logisticsOrderService.saveCancel(id, remark);
    }

    @ApiOperation(value = "同步德邦物流订单",notes = "同步德邦物流订单")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    @PostMapping(value = "/saveSync")
    public Result saveSync(Long id) {
        return logisticsOrderService.saveSync(id);
    }

    @ApiOperation(value = "同步德邦物流订单",notes = "同步德邦物流订单")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    @PostMapping(value = "/saveSyncBusiness")
    public Result saveSyncBusiness(Long id) {
        return logisticsOrderService.saveSyncBusiness(id);
    }

    @ApiOperation(value = "网点查询",notes = "网点查询")
    @PostMapping(value = "/queryWebsiteList")
    public Result<DepponWebsiteListVO> queryWebsiteList(DepponWebsiteBO bo) {
        return logisticsOrderService.queryWebsiteList(bo);
    }

    @ApiOperation(value = "价格试算",notes = "价格试算")
    @PostMapping(value = "/saveBudget")
    public Result<List<DepponBudgetVO>> saveBudget(DepponBudgetBO bo) {
        return logisticsOrderService.saveBudget(bo);
    }


    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<LogisticsOrderVO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        return logisticsOrderService.get(id);
    }

    @ApiOperation(value = "物流订单表列表",notes = "物流订单表列表")
    @PostMapping("/queryPageList")
    public Result<Page<LogisticsOrderVO>> queryPageList(LogisticsOrderBO bo){
        return logisticsOrderService.queryPageList(bo);
    }
}
